package learn_concurrent._11;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

public class AtomicReferenceFieldUpdaterTest {
	
	public static void main(String[] args) {
		Student student = new Student();
		
		AtomicReferenceFieldUpdater<Student,String> updater = 
				AtomicReferenceFieldUpdater.newUpdater(Student.class, String.class, "name");
		
		boolean success = updater.compareAndSet(student, student.getName(), "Tom");
		System.out.println(success);
		System.out.println(student);
	}
	
}

class Student {
	volatile String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return "Student [name=" + name + "]";
	}
	
}
